﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Messaging;

namespace Mal.Balades.Admin.ViewModels
{
    public class MainViewModel : ViewModelBase
    {
        #region Fields
        private string messageBarText;
        private bool messageBarVisible;



        #endregion

        #region Construction / Destruction
        public MainViewModel()
        {
            if (this.IsInDesignMode)
            {
                this.MessageBarText = "Loading ...";
            }

            Messenger.Default.Register<MessageBarMessage>(this, OnMessageBarMessage);
        }
        #endregion

        #region enum, struct, class
        public class MessageBarMessage : MessageBase
        {
            public string Message { get; private set; }
            public bool ShowMessage { get; private set; }

            public MessageBarMessage(object sender, string message)
                : base(sender)
            {
                this.Message = message;
                this.ShowMessage = true;
            }

            public MessageBarMessage(object sender)
                : base(sender)
            {
                this.Message = string.Empty;
                this.ShowMessage = false;
            }
        }
        #endregion

        #region Properties
        public bool MessageBarVisible
        {
            get { return messageBarVisible; }
            set
            {
                if (messageBarVisible != value)
                {
                    messageBarVisible = value;
                    RaisePropertyChanged("MessageBarVisible");
                }
            }
        }

        public string MessageBarText
        {
            get { return messageBarText; }
            set
            {
                if (messageBarText != value)
                {
                    messageBarText = value;
                    RaisePropertyChanged("MessageBarText");
                }
            }
        }
        #endregion

        #region Methods

        #endregion

        #region Events
        public void OnMessageBarMessage(MessageBarMessage message)
        {
            this.MessageBarText = message.Message;
            this.MessageBarVisible = message.ShowMessage;
        }
        #endregion


    }
}
